package com.yitiao.base.reflects;

import java.lang.reflect.Field;

public class FieldSimple {
    public static void main(String[] args) throws Exception {
        People people = new People("zs",12);
        Class<? extends People> peopleClass = people.getClass();
        Field[] fields = peopleClass.getDeclaredFields();
        for (Field field : fields) {
            String fieldName = field.getName(); // 获取字段名称
            Class<?> fieldType = field.getType();
            Field declaredField = peopleClass.getDeclaredField(fieldName);
            // 设置属性的可访问性
            declaredField.setAccessible(true);
            Object object = declaredField.get(people);
            System.out.println(fieldName+"-"+fieldType+"-"+object.toString());
            // 其他操作，如获取字段值等
        }
    }
}
